﻿unit CmEnterpriseEmpBLL;

interface
{$I ../../Config.inc}
uses
  FastMM4,
  FastMove,
  System.SysUtils,
  System.Classes,
  System.Types,
  System.StrUtils,
  System.DateUtils,
  Winapi.Windows,
  Data.DB,
  Data.Win.ADODB,
  Datasnap.DBClient,
  Datasnap.Provider,
  {$IFDEF UNICODE}
  AnsiStrings,
  {$ENDIF }
  QBParcel,
  DllSpread,
  Generics.Collections,
  QJson,
  UserConnection,
  DBAccessor,
  DllPlugin,
  SK0001Comm,
  CmEnterpriseEmpModel,
  CmEnterpriseEmpDAL;

type
 TCmEnterpriseEmpBLL = class(TObject)
  private
  
  protected
    fServConn:TADOConnection;
    
  {$IFDEF SERVER}
    fDBConn:TADOConnection;
    fDBID:string;
  {$ENDIF}
  {$IFDEF CLIENT}
    fDllPlugin:TDllPlugin;
    fPluginID:string;
  {$ENDIF}
    
  public
  {$IFDEF SERVER}
    constructor Create(const iServerConn,iDBConn:TADOConnection; const iDBID:string);overload;
  {$ENDIF}
  {$IFDEF CLIENT}
    constructor Create(const iServerConn:TADOConnection);overload;
  {$ENDIF}
    destructor Destroy;override;
    
  {$IFDEF SERVER}
    function BeforeTreatment(const iItem:TCmEnterpriseEmp; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;overload;virtual;
    function BeforeTreatment(const iItems:TCmEnterpriseEmpList; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;overload;virtual;
    
    function BeforeCheck(const iItem:TCmEnterpriseEmp; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;overload;virtual;
    function BeforeCheck(const iItems:TCmEnterpriseEmpList; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;overload;virtual;
    
    function Check(const iItem:TCmEnterpriseEmp; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;overload;virtual;
    function Check(const iItems:TCmEnterpriseEmpList; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;overload;virtual;
  
    function BeforeExecute(const iItem:TCmEnterpriseEmp; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;overload;virtual;
    function BeforeExecute(const iItems:TCmEnterpriseEmpList; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;overload;virtual;
    
    function AfterTreatment(const iItem:TCmEnterpriseEmp; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;overload;virtual;
    function AfterTreatment(const iItems:TCmEnterpriseEmpList; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;overload;virtual;
  {$ENDIF}
    
    function GetCDSModel(var iCDS:TClientDataSet; out oError:string; const dLoadMode:eDBLoadMode=eDBLoadMode.dblmTable):Boolean;
    
    function Reload(const iItem:TCmEnterpriseEmp; out oError:string):Boolean;overload;
    function Reload(const iItems:TCmEnterpriseEmpList; out oError:string):Boolean;overload;
    
    function LoadByCondition(const iItem:TCmEnterpriseEmp; const iCondition:string; out oError:string; const dLoadMode:eDBLoadMode=eDBLoadMode.dblmTable):Boolean;overload;
    function LoadByCondition(const iItems:TCmEnterpriseEmpList; const iCondition:string; out oError:string; const dOrderBy:string=''; const dLoadMode:eDBLoadMode=eDBLoadMode.dblmTable):Boolean;overload;
    function LoadByPageQuery(const iItems:TCmEnterpriseEmpList; const iPageNo:Integer; const iPageSize:Integer; const iCondition,iOrderBy:string; out oTotalCount:Integer; out oError:string; const dLoadMode:eDBLoadMode=eDBLoadMode.dblmTable):Boolean;
  
    function Add(const iItem:TCmEnterpriseEmp; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;overload;
    function Add(const iItems:TCmEnterpriseEmpList; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;overload;
    function GetAddSQLs(const iItem:TCmEnterpriseEmp; const iSQLs:TStrings; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;overload;
    function GetAddSQLs(const iItems:TCmEnterpriseEmpList; const iSQLs:TStrings; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;overload;
    
    function Edit(const iItem:TCmEnterpriseEmp; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;overload;
    function Edit(const iItems:TCmEnterpriseEmpList; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;overload;
    function GetEditSQLs(const iItem:TCmEnterpriseEmp; const iSQLs:TStrings; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;overload;
    function GetEditSQLs(const iItems:TCmEnterpriseEmpList; const iSQLs:TStrings; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;overload;
    
    function Delete(const iItem:TCmEnterpriseEmp; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;overload;
    function Delete(const iItems:TCmEnterpriseEmpList; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;overload;
    function GetDeleteSQLs(const iItem:TCmEnterpriseEmp; const iSQLs:TStrings; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;overload;
    function GetDeleteSQLs(const iItems:TCmEnterpriseEmpList; const iSQLs:TStrings; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;overload;
  end;
implementation
{$IFDEF SERVER}
constructor TCmEnterpriseEmpBLL.Create(const iServerConn,iDBConn:TADOConnection; const iDBID:string);
begin
  inherited Create;
  
  fServConn:=iServerConn;
  fDBConn:=iDBConn;
  fDBID:=iDBID;
end;
{$ENDIF}
{$IFDEF CLIENT}
constructor TCmEnterpriseEmpBLL.Create(const iServerConn:TADOConnection);
begin
  inherited Create;
  
  fServConn:=iServerConn;
  fPluginID:='SK0001Manager';
  fDllPlugin:=TDllPlugin.Create(nil);
  fDllPlugin.UserConnection:=fServConn;
  fDllPlugin.TargetNodeId:=fServConn.UserNodeId;
end;
{$ENDIF}

destructor TCmEnterpriseEmpBLL.Destroy;
begin
{$IFDEF SERVER}

{$ENDIF}
{$IFDEF CLIENT}
  FreeAndNil(fDllPlugin);
{$ENDIF}
  inherited Destroy;
end;

{$IFDEF SERVER}
function TCmEnterpriseEmpBLL.BeforeTreatment(const iItem:TCmEnterpriseEmp; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;
begin
  Result:=True;
end;

function TCmEnterpriseEmpBLL.BeforeTreatment(const iItems:TCmEnterpriseEmpList; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;
begin
  Result:=True;
end;

function TCmEnterpriseEmpBLL.BeforeCheck(const iItem:TCmEnterpriseEmp; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;
begin
  Result:=True;
end;

function TCmEnterpriseEmpBLL.BeforeCheck(const iItems:TCmEnterpriseEmpList; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;
begin
  Result:=True;
end;

function TCmEnterpriseEmpBLL.Check(const iItem:TCmEnterpriseEmp; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;
begin
  Result:=True;
end;

function TCmEnterpriseEmpBLL.Check(const iItems:TCmEnterpriseEmpList; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;
begin
  Result:=True;
end;

function TCmEnterpriseEmpBLL.BeforeExecute(const iItem:TCmEnterpriseEmp; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;
begin
  Result:=True;
end;

function TCmEnterpriseEmpBLL.BeforeExecute(const iItems:TCmEnterpriseEmpList; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;
begin
  Result:=True;
end;

function TCmEnterpriseEmpBLL.AfterTreatment(const iItem:TCmEnterpriseEmp; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;
begin
  Result:=True;
end;

function TCmEnterpriseEmpBLL.AfterTreatment(const iItems:TCmEnterpriseEmpList; const iPreMode:ePretreatmentMode; const iParcel:TQBParcel; out oError:string):Boolean;
begin
  Result:=True;
end;
{$ENDIF}

function TCmEnterpriseEmpBLL.GetCDSModel(var iCDS:TClientDataSet; out oError:string; const dLoadMode:eDBLoadMode):Boolean;
{$IFDEF SERVER}
var
  ItemDal:TCmEnterpriseEmpDAL;
begin
  if (iCDS<>nil) then
  begin
    ItemDal:=TCmEnterpriseEmpDAL.Create(fDBConn,fDBID);
    try
      if not ItemDal.GetCDSModel(iCDS,dLoadMode,oError) then
      begin
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(ItemDal);
    end;
  end else begin
    oError:=Format(string('调用%s.GetCDSModel函数错误!错误内容:传入的数据集对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF} {$IFDEF CLIENT}
var
  InParcel,OutParcel:TQBParcel;
  ErrorCode,ErrorText:string;
begin
  if (iCDS<>nil) then
  begin
    InParcel:=TQBParcel.Create;
    OutParcel:=TQBParcel.Create;
    try
      InParcel.PutAnsiStringGoods(AnsiString('Fn'),AnsiString('GetCDSModel'));
      InParcel.PutAnsiStringGoods(AnsiString('ObjName'),AnsiString('TCmEnterpriseEmp'));
      InParcel.PutIntegerGoods(AnsiString('DBLoadMode'),Ord(dLoadMode));
      if fDllPlugin.BinaryRPC(AnsiString(fPluginID),EmptyAnsiStr,InParcel,OutParcel) then
      begin
        if not OutParcel.GoodsExists('error') then
        begin
          OutParcel.GetCDSGoods(AnsiString('CDSModel'),iCDS);
        end else begin
          oError:=Format(string('调用%s.GetCDSModel函数-->调用%s插件-->%s'),[Self.ClassName,fPluginID,string(OutParcel.GetAnsiStringGoods('error'))]);
          Result:=False;
          Exit;
        end;
      end else begin
        fDllPlugin.GetLastError(ErrorCode,ErrorText);
        oError:=Format(string('调用%s.GetCDSModel函数-->调用%s插件错误!错误代码:%s 错误内容:%s'),[Self.ClassName,fPluginID,ErrorCode,ErrorText]);
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(InParcel);
      FreeAndNil(OutParcel);
    end;
  end else begin
    oError:=Format(string('调用%s.GetCDSModel函数错误!错误内容:传入的数据集对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF}

function TCmEnterpriseEmpBLL.Reload(const iItem:TCmEnterpriseEmp; out oError:string):Boolean;
{$IFDEF SERVER}
var
  ItemDal:TCmEnterpriseEmpDAL;
  Condition:string;
begin
  if (iItem<>nil) then
  begin
    ItemDal:=TCmEnterpriseEmpDAL.Create(fDBConn,fDBID);
    try
      Condition:=Format(string('%s=''%s'' and %s=''%s'' and %s=%d and %s=''%s'''),[TCmEnterpriseEmpModel.cEnterpriseIdKey,iItem.EnterpriseId,TCmEnterpriseEmpModel.cEmpIdKey,iItem.EmpId,TCmEnterpriseEmpModel.cEmpTypeKey,iItem.EmpType,TCmEnterpriseEmpModel.cOrgIdKey,iItem.OrgId]);
      if not ItemDal.LoadByCondition(iItem,Condition,eDBLoadMode.dblmTable,oError) then
      begin
        oError:=Format(string('调用%s.Reload单例函数-->%s'),[Self.ClassName,oError]);
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(ItemDal);
    end;
  end else begin
    oError:=Format(string('调用%s.Reload单例函数错误!错误内容:传入的实体对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF} {$IFDEF CLIENT}
var
  InParcel,OutParcel:TQBParcel;
  ErrorCode,ErrorText:string;
begin
  if (iItem<>nil) then
  begin
    InParcel:=TQBParcel.Create;
    OutParcel:=TQBParcel.Create;
    try
      InParcel.PutAnsiStringGoods(AnsiString('Fn'),AnsiString('Reload'));
      InParcel.PutAnsiStringGoods(AnsiString('ObjName'),AnsiString(iItem.ClassName));
      InParcel.PutAnsiStringGoods(AnsiString('ObjStr'),AnsiString(iItem.SaveToStr));
      if fDllPlugin.BinaryRPC(AnsiString(fPluginID),EmptyAnsiStr,InParcel,OutParcel) then
      begin
        if not OutParcel.GoodsExists('error') then
        begin
          if not iItem.LoadFromStr(string(OutParcel.GetAnsiStringGoods(AnsiString('ObjStr'))),oError) then
          begin
            oError:=Format(string('调用%s.Reload单例函数-->%s'),[Self.ClassName,oError]);
            Result:=False;
            Exit;
          end;
        end else begin
          oError:=Format(string('调用%s.Reload单例函数->调用%s插件-->%s'),[Self.ClassName,fPluginID,string(OutParcel.GetAnsiStringGoods('error'))]);
          Result:=False;
          Exit;
        end;
      end else begin
        fDllPlugin.GetLastError(ErrorCode,ErrorText);
        oError:=Format(string('调用%s.Reload单例函数-->调用%s插件错误! 错误代码:%s 错误内容:%s'),[Self.ClassName,fPluginID,ErrorCode,ErrorText]);
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(InParcel);
      FreeAndNil(OutParcel);
    end;
  end else begin
    oError:=Format(string('调用%s.Reload单例函数! 错误内容:传入的实体对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF}

function TCmEnterpriseEmpBLL.Reload(const iItems:TCmEnterpriseEmpList; out oError:string):Boolean;
{$IFDEF SERVER}
var
  ItemDal:TCmEnterpriseEmpDAL;
  DBItems:TCmEnterpriseEmpList;
  Item,DBItem:TCmEnterpriseEmp;
  Condition:string;
  iItemsIndex,DBItemsIndex:Integer;
  AlreadyUseItemKeyList:TStrings;
  FindItemFlg:Boolean;
begin
  if (iItems<>nil) then
  begin
    ItemDal:=TCmEnterpriseEmpDAL.Create(fDBConn,fDBID);
    DBItems:=TCmEnterpriseEmpList.Create;
    AlreadyUseItemKeyList:=TStringList.Create;
    try
      Condition:=EmptyStr;
      for iItemsIndex := 0 to iItems.SortKeys.Count-1 do
      begin
        Item:=iItems.FindByKey(iItems.SortKeys.Strings[iItemsIndex]);
        if Item<>nil then
        begin
          if iItemsIndex=0 then
          begin
            Condition:=Condition+Format(string('(%s)'),[Format(string('%s=''%s'' and %s=''%s'' and %s=%d and %s=''%s'''),[TCmEnterpriseEmpModel.cEnterpriseIdKey,Item.EnterpriseId,TCmEnterpriseEmpModel.cEmpIdKey,Item.EmpId,TCmEnterpriseEmpModel.cEmpTypeKey,Item.EmpType,TCmEnterpriseEmpModel.cOrgIdKey,Item.OrgId])]);
          end else begin
            Condition:=Condition+Format(string('or (%s)'),[Format(string('%s=''%s'' and %s=''%s'' and %s=%d and %s=''%s'''),[TCmEnterpriseEmpModel.cEnterpriseIdKey,Item.EnterpriseId,TCmEnterpriseEmpModel.cEmpIdKey,Item.EmpId,TCmEnterpriseEmpModel.cEmpTypeKey,Item.EmpType,TCmEnterpriseEmpModel.cOrgIdKey,Item.OrgId])]);
          end;
        end else begin
          oError:=Format(string('调用%s.Reload列表函数错误!错误内容:拼装对象列表条件时对象缺失 主键号:%s!'),[Self.ClassName,iItems.SortKeys.Strings[iItemsIndex]]);
          Result:=False;
          Exit;
        end;
      end;

      if ItemDal.LoadByCondition(DBItems,Condition,eDBLoadMode.dblmTable,oError) then
      begin
        for iItemsIndex := 0 to iItems.SortKeys.Count-1 do
        begin
          Item:=iItems.FindByKey(iItems.SortKeys.Strings[iItemsIndex]);
          if Item=nil then
          begin
            oError:=Format(string('调用%s.Reload列表函数错误! 错误内容:装载对象列表时对象缺失 主键号:%s!'),[Self.ClassName,iItems.SortKeys.Strings[iItemsIndex]]);
            Result:=False;
            Exit;
          end;
          FindItemFlg:=False;
          for DBItemsIndex := 0 to DBItems.SortKeys.Count-1 do
          begin
            if -1=AlreadyUseItemKeyList.IndexOf(DBItems.SortKeys.Strings[DBItemsIndex]) then
            begin
              DBItem:=DBItems.FindByKey(DBItems.SortKeys.Strings[DBItemsIndex]);
              if DBItem=nil then
              begin
                oError:=Format(string('调用%s.Reload列表函数错误! 错误内容:装载对象列表时数据库对象缺失 主键号:%s!'),[Self.ClassName,DBItems.SortKeys.Strings[DBItemsIndex]]);
                Result:=False;
                Exit;
              end;

              if SameStr(Item.EnterpriseId,DBItem.EnterpriseId) and SameStr(Item.EmpId,DBItem.EmpId) and (Item.EmpType=DBItem.EmpType) and SameStr(Item.OrgId,DBItem.OrgId) then
              begin
                if Item.LoadFromStr(DBItem.SaveToStr,oError) then
                begin
                  FindItemFlg:=True;
                  AlreadyUseItemKeyList.Add(DBItem.ObjGUID);
                  iItems.SortKeys.Strings[iItemsIndex]:=Item.ObjGUID;
                end else begin
                  oError:=Format(string('调用%s.Reload列表函数-->%s'),[Self.ClassName,oError]);
                  Result:=False;
                  Exit;
                end;
              end;
            end;
          end;
          if not FindItemFlg then
          begin
            oError:=Format(string('调用%s.Reload列表函数错误! 错误内容:装载对象列表时未匹配到对象 主键号:%s!'),[Self.ClassName,iItems.SortKeys.Strings[iItemsIndex]]);
            Result:=False;
            Exit;
          end;
        end;
      end else begin
        oError:=Format(string('调用%s.Reload列表函数-->%s'),[Self.ClassName,oError]);
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(ItemDal);
      FreeAndNil(DBItems);
      FreeAndNil(AlreadyUseItemKeyList);
    end;
  end else begin
    oError:=Format(string('调用%s.Reload列表函数错误!错误内容:传入的实体列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF} {$IFDEF CLIENT}
var
  InParcel,OutParcel:TQBParcel;
  ErrorCode,ErrorText:string;
begin
  if (iItems<>nil) then
  begin
    InParcel:=TQBParcel.Create;
    OutParcel:=TQBParcel.Create;
    try
      InParcel.PutAnsiStringGoods(AnsiString('Fn'),AnsiString('Reload'));
      InParcel.PutAnsiStringGoods(AnsiString('ObjName'),AnsiString(iItems.ClassName));
      InParcel.PutAnsiStringGoods(AnsiString('ObjStr'),AnsiString(iItems.SaveToStr));
      if fDllPlugin.BinaryRPC(AnsiString(fPluginID),EmptyAnsiStr,InParcel,OutParcel) then
      begin
        if not OutParcel.GoodsExists('error') then
        begin
          if not iItems.LoadFromStr(string(OutParcel.GetAnsiStringGoods(AnsiString('ObjStr'))),oError) then
          begin
            oError:=Format(string('调用%s.Reload列表函数错误-->%s'),[Self.ClassName,oError]);
            Result:=False;
            Exit;
          end;
        end else begin
          oError:=Format(string('调用%s.Reload列表函数错误-->调用%s插件-->%s'),[Self.ClassName,fPluginID,string(OutParcel.GetAnsiStringGoods('error'))]);
          Result:=False;
          Exit;
        end;
      end else begin
        fDllPlugin.GetLastError(ErrorCode,ErrorText);
        oError:=Format(string('调用%s.Reload列表函数错误-->调用%s插件错误! 错误代码:%s 错误内容:%s'),[Self.ClassName,fPluginID,ErrorCode,ErrorText]);
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(InParcel);
      FreeAndNil(OutParcel);
    end;
  end else begin
    oError:=Format(string('调用%s.Reload列表函数错误! 错误内容:传入的实体列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF}

function TCmEnterpriseEmpBLL.LoadByCondition(const iItem:TCmEnterpriseEmp; const iCondition:string; out oError:string; const dLoadMode:eDBLoadMode):Boolean;
{$IFDEF SERVER}
var
  ItemDal:TCmEnterpriseEmpDAL;
begin
  if (iItem<>nil) and (not SameStr(Trim(iCondition),EmptyStr)) then
  begin
    ItemDal:=TCmEnterpriseEmpDAL.Create(fDBConn,fDBID);
    try
      if not ItemDal.LoadByCondition(iItem,iCondition,dLoadMode,oError) then
      begin
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(ItemDal);
    end;
  end else begin
    oError:=Format(string('调用%s.LoadByCondition单例函数错误!错误内容:传入的实体对象为空或者查询条件为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF} {$IFDEF CLIENT}
var
  InParcel,OutParcel:TQBParcel;
  ErrorCode,ErrorText:string;
begin
  if (iItem<>nil) and (not SameStr(Trim(iCondition),EmptyStr)) then
  begin
    InParcel:=TQBParcel.Create;
    OutParcel:=TQBParcel.Create;
    try
      InParcel.PutAnsiStringGoods(AnsiString('Fn'),AnsiString('GetByCondition'));
      InParcel.PutAnsiStringGoods(AnsiString('ObjName'),AnsiString(iItem.ClassName));
      InParcel.PutAnsiStringGoods(AnsiString('Condition'),AnsiString(iCondition));
      InParcel.PutAnsiStringGoods(AnsiString('OrderBy'),EmptyAnsiStr);
      InParcel.PutIntegerGoods(AnsiString('DBLoadMode'),Ord(dLoadMode));
      if fDllPlugin.BinaryRPC(AnsiString(fPluginID),EmptyAnsiStr,InParcel,OutParcel) then
      begin
        if not OutParcel.GoodsExists('error') then
        begin
          if not iItem.LoadFromStr(string(OutParcel.GetAnsiStringGoods(AnsiString('ObjStr'))),oError) then
          begin
            oError:=Format(string('调用%s.LoadByCondition单例函数-->%s'),[Self.ClassName,oError]);
            Result:=False;
            Exit;
          end;
        end else begin
          oError:=Format(string('调用%s.LoadByCondition单例函数->调用%s插件-->%s'),[Self.ClassName,fPluginID,string(OutParcel.GetAnsiStringGoods('error'))]);
          Result:=False;
          Exit;
        end;
      end else begin
        fDllPlugin.GetLastError(ErrorCode,ErrorText);
        oError:=Format(string('调用%s.LoadByCondition单例函数-->调用%s插件错误! 错误代码:%s 错误内容:%s'),[Self.ClassName,fPluginID,ErrorCode,ErrorText]);
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(InParcel);
      FreeAndNil(OutParcel);
    end;
  end else begin
    oError:=Format(string('调用%s.LoadByCondition单例函数错误!错误内容:传入的实体对象为空或者查询条件为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF}

function TCmEnterpriseEmpBLL.LoadByCondition(const iItems:TCmEnterpriseEmpList; const iCondition:string; out oError:string; const dOrderBy:string; const dLoadMode:eDBLoadMode):Boolean;
{$IFDEF SERVER}
var
  ItemDal:TCmEnterpriseEmpDAL;
begin
  if (iItems<>nil) then
  begin
    ItemDal:=TCmEnterpriseEmpDAL.Create(fDBConn,fDBID);
    try
      if not ItemDal.LoadByCondition(iItems,iCondition,dLoadMode,oError,dOrderBy) then
      begin
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(ItemDal);
    end;
  end else begin
    oError:=Format(string('调用%s.LoadByCondition列表函数错误!错误内容:传入的实体列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF} {$IFDEF CLIENT}
var
  InParcel,OutParcel:TQBParcel;
  ErrorCode,ErrorText:string;
begin
  if (iItems<>nil) then
  begin
    InParcel:=TQBParcel.Create;
    OutParcel:=TQBParcel.Create;
    try
      InParcel.PutAnsiStringGoods(AnsiString('Fn'),AnsiString('GetByCondition'));
      InParcel.PutAnsiStringGoods(AnsiString('ObjName'),AnsiString(iItems.ClassName));
      InParcel.PutAnsiStringGoods(AnsiString('Condition'),AnsiString(iCondition));
      InParcel.PutAnsiStringGoods(AnsiString('OrderBy'),AnsiString(dOrderBy));
      InParcel.PutIntegerGoods(AnsiString('DBLoadMode'),Ord(dLoadMode));
      if fDllPlugin.BinaryRPC(AnsiString(fPluginID),EmptyAnsiStr,InParcel,OutParcel) then
      begin
        if not OutParcel.GoodsExists('error') then
        begin
          if not iItems.LoadFromStr(string(OutParcel.GetAnsiStringGoods(AnsiString('ObjStr'))),oError) then
          begin
            oError:=Format(string('调用%s.LoadByCondition列表函数-->%s'),[Self.ClassName,oError]);
            Result:=False;
            Exit;
          end;
        end else begin
          oError:=Format(string('调用%s.LoadByCondition列表函数-->调用%s插件-->%s'),[Self.ClassName,fPluginID,string(OutParcel.GetAnsiStringGoods('error'))]);
          Result:=False;
          Exit;
        end;
      end else begin
        fDllPlugin.GetLastError(ErrorCode,ErrorText);
        oError:=Format(string('调用%s.LoadByCondition列表函数错误-->调用%s插件错误! 错误代码:%s 错误内容:%s'),[Self.ClassName,fPluginID,ErrorCode,ErrorText]);
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(InParcel);
      FreeAndNil(OutParcel);
    end;
  end else begin
    oError:=Format(string('调用%s.LoadByCondition列表函数错误! 错误内容:传入的实体列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF}

function TCmEnterpriseEmpBLL.LoadByPageQuery(const iItems:TCmEnterpriseEmpList; const iPageNo:Integer; const iPageSize:Integer; const iCondition,iOrderBy:string; out oTotalCount:Integer; out oError:string; const dLoadMode:eDBLoadMode):Boolean;
{$IFDEF SERVER}
var
  ItemDal:TCmEnterpriseEmpDAL;
begin
  if (iItems<>nil) and (iPageNo>0) and (iPageSize>0) and not SameStr(Trim(iOrderBy),EmptyStr) then
  begin
    ItemDal:=TCmEnterpriseEmpDAL.Create(fDBConn,fDBID);
    try
      if not ItemDal.LoadByPageQuery(iItems,iPageNo,iPageSize,iCondition,iOrderBy,dLoadMode,oTotalCount,oError) then
      begin
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(ItemDal);
    end;
  end else begin
    oError:=Format(string('调用%s.LoadByPageQuery列表函数错误!错误内容:传入的实体列表对象为空或者排序参数为空或者页号、页大小非法!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF} {$IFDEF CLIENT}
var
  InParcel,OutParcel:TQBParcel;
  ErrorCode,ErrorText:string;
begin
  if (iItems<>nil) and (iPageNo>0) and (iPageSize>0) and not SameStr(Trim(iOrderBy),EmptyStr) then
  begin
    InParcel:=TQBParcel.Create;
    OutParcel:=TQBParcel.Create;
    try
      InParcel.PutAnsiStringGoods(AnsiString('Fn'),AnsiString('GetByPageQuery'));
      InParcel.PutAnsiStringGoods(AnsiString('ObjName'),AnsiString(iItems.ClassName));
      InParcel.PutIntegerGoods(AnsiString('PageNo'),iPageNo);
      InParcel.PutIntegerGoods(AnsiString('PageSize'),iPageSize);
      InParcel.PutAnsiStringGoods(AnsiString('Condition'),AnsiString(iCondition));
      InParcel.PutAnsiStringGoods(AnsiString('OrderBy'),AnsiString(iOrderBy));
      InParcel.PutIntegerGoods(AnsiString('DBLoadMode'),Ord(dLoadMode));
      if fDllPlugin.BinaryRPC(AnsiString(fPluginID),EmptyAnsiStr,InParcel,OutParcel) then
      begin
        if not OutParcel.GoodsExists('error') then
        begin
          if iItems.LoadFromStr(string(OutParcel.GetAnsiStringGoods(AnsiString('ObjStr'))),oError) then
          begin
            oTotalCount:=OutParcel.GetIntegerGoods(AnsiString('TotalCount'));
          end else begin
            oError:=Format(string('调用%s.LoadByPageQuery列表函数-->%s'),[Self.ClassName,oError]);
            Result:=False;
            Exit;
          end;
        end else begin
          oError:=Format(string('调用%s.LoadByPageQuery列表函数错误-->调用%s插件-->%s'),[Self.ClassName,fPluginID,string(OutParcel.GetAnsiStringGoods('error'))]);
          Result:=False;
          Exit;
        end;
      end else begin
        fDllPlugin.GetLastError(ErrorCode,ErrorText);
        oError:=Format(string('调用%s.LoadByPageQuery列表函数错误-->调用%s插件错误!错误代码:%s 错误内容:%s'),[Self.ClassName,fPluginID,ErrorCode,ErrorText]);
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(InParcel);
      FreeAndNil(OutParcel);
    end;
  end else begin
    oError:=Format(string('调用%s.LoadByPageQuery列表函数错误! 错误内容:传入的实体列表对象为空或者排序参数为空或者页号、页大小非法!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF}

function TCmEnterpriseEmpBLL.Add(const iItem:TCmEnterpriseEmp; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;
{$IFDEF SERVER}
var
  ItemDal:TCmEnterpriseEmpDAL;
  CreateParcelFlg:Boolean;
begin
  if (iItem<>nil) then
  begin
    ItemDal:=TCmEnterpriseEmpDAL.Create(fDBConn,fDBID);
    if dParcel=nil then
    begin
      dParcel:=TQBParcel.Create;;
      CreateParcelFlg:=True;
    end else begin
      CreateParcelFlg:=False;
    end;
    
    try
      if not BeforeTreatment(iItem,pmAdd,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
     
      if dIsCheck then
      begin
        if not BeforeCheck(iItem,pmAdd,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      
        if not Check(iItem,pmAdd,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      end;
      
      if not BeforeExecute(iItem,pmAdd,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
        
      if ItemDal.InsertToDB(iItem,oError) and 
        Reload(iItem,oError) then
      begin
      
      end else begin
        oError:=Format(string('调用%s.Add单例函数-->%s'),[Self.ClassName,oError]);
        Result:=False;
        Exit;
      end;
      
      if not AfterTreatment(iItem,pmAdd,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
    finally
      FreeAndNil(ItemDal);
      if CreateParcelFlg then
      begin
        FreeAndNil(dParcel);
      end;
    end;
  end else begin
    oError:=Format(string('调用%s.Add单例函数错误!错误内容:传入的实体对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF} {$IFDEF CLIENT}
var
  InParcel,OutParcel:TQBParcel;
  ErrorCode,ErrorText:string;
begin
  if (iItem<>nil) then
  begin
    InParcel:=TQBParcel.Create;
    OutParcel:=TQBParcel.Create;
    try
      InParcel.PutAnsiStringGoods(AnsiString('Fn'),AnsiString('SaveToDB'));
      InParcel.PutAnsiStringGoods(AnsiString('ObjName'),AnsiString(iItem.ClassName));
      InParcel.PutIntegerGoods(AnsiString('Method'),Ord(ePretreatmentMode.pmAdd));
      InParcel.PutAnsiStringGoods(AnsiString('ObjStr'),AnsiString(iItem.SaveToStr));
      InParcel.PutBooleanGoods(AnsiString('IsCheck'),dIsCheck);
      if fDllPlugin.BinaryRPC(AnsiString(fPluginID),EmptyAnsiStr,InParcel,OutParcel) then
      begin
        if not OutParcel.GoodsExists('error') then
        begin
          if not iItem.LoadFromStr(string(OutParcel.GetAnsiStringGoods(AnsiString('ObjStr'))),oError) then
          begin
            oError:=Format(string('调用%s.Add单例函数-->%s'),[Self.ClassName,oError]);
            Result:=False;
            Exit;
          end;
        end else begin
          oError:=Format(string('调用%s.Add单例函数-->调用%s插件-->%s'),[Self.ClassName,fPluginID,string(OutParcel.GetAnsiStringGoods('error'))]);
          Result:=False;
          Exit;
        end;
      end else begin
        fDllPlugin.GetLastError(ErrorCode,ErrorText);
        oError:=Format(string('调用%s.Add单例函数-->调用%s插件错误!错误代码:%s 错误内容:%s'),[Self.ClassName,fPluginID,ErrorCode,ErrorText]);
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(InParcel);
      FreeAndNil(OutParcel);
    end;
  end else begin
    oError:=Format(string('调用%s.Add单例函数错误!错误内容:传入的实体对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF}

function TCmEnterpriseEmpBLL.Add(const iItems:TCmEnterpriseEmpList; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;
{$IFDEF SERVER}
var
  ItemDal:TCmEnterpriseEmpDAL;
  CreateParcelFlg:Boolean;
begin
  if (iItems<>nil) then
  begin
    ItemDal:=TCmEnterpriseEmpDAL.Create(fDBConn,fDBID);
    if dParcel=nil then
    begin
      dParcel:=TQBParcel.Create;;
      CreateParcelFlg:=True;
    end else begin
      CreateParcelFlg:=False;
    end;
    
    try
      if not BeforeTreatment(iItems,pmAdd,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if dIsCheck then
      begin
        if not BeforeCheck(iItems,pmAdd,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      
        if not Check(iItems,pmAdd,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      end;
      
      if not BeforeExecute(iItems,pmAdd,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if ItemDal.InsertToDB(iItems,oError) and 
        Reload(iItems,oError) then
      begin
      
      end else begin
        oError:=Format(string('调用%s.Add列表函数-->%s'),[Self.ClassName,oError]);
        Result:=False;
        Exit;
      end;
      
      if not AfterTreatment(iItems,pmAdd,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
    finally
      FreeAndNil(ItemDal);
      if CreateParcelFlg then
      begin
        FreeAndNil(dParcel);
      end;
    end;
  end else begin
    oError:=Format(string('调用%s.Add列表函数错误!错误内容:传入的实体列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF} {$IFDEF CLIENT}
var
  InParcel,OutParcel:TQBParcel;
  ErrorCode,ErrorText:string;
begin
  if (iItems<>nil) then
  begin
    InParcel:=TQBParcel.Create;
    OutParcel:=TQBParcel.Create;
    try
      InParcel.PutAnsiStringGoods(AnsiString('Fn'),AnsiString('SaveToDB'));
      InParcel.PutAnsiStringGoods(AnsiString('ObjName'),AnsiString(iItems.ClassName));
      InParcel.PutIntegerGoods(AnsiString('Method'),Ord(ePretreatmentMode.pmAdd));
      InParcel.PutAnsiStringGoods(AnsiString('ObjStr'),AnsiString(iItems.SaveToStr));
      InParcel.PutBooleanGoods(AnsiString('IsCheck'),dIsCheck);
      if fDllPlugin.BinaryRPC(AnsiString(fPluginID),EmptyAnsiStr,InParcel,OutParcel) then
      begin
        if not OutParcel.GoodsExists('error') then
        begin
          if not iItems.LoadFromStr(string(OutParcel.GetAnsiStringGoods(AnsiString('ObjStr'))),oError) then
          begin
            oError:=Format(string('调用%s.Add列表函数-->%s'),[Self.ClassName,oError]);
            Result:=False;
            Exit;
          end;
        end else begin
          oError:=Format(string('调用%s.Add列表函数-->调用%s插件-->%s'),[Self.ClassName,fPluginID,string(OutParcel.GetAnsiStringGoods('error'))]);
          Result:=False;
          Exit;
        end;
      end else begin
        fDllPlugin.GetLastError(ErrorCode,ErrorText);
        oError:=Format(string('调用%s.Add列表函数->调用%s插件错误! 错误代码:%s 错误内容:%s'),[Self.ClassName,fPluginID,ErrorCode,ErrorText]);
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(InParcel);
      FreeAndNil(OutParcel);
    end;
  end else begin
    oError:=Format(string('调用%s.Add列表函数错误!错误内容:传入的实体列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF}

function TCmEnterpriseEmpBLL.GetAddSQLs(const iItem:TCmEnterpriseEmp; const iSQLs:TStrings; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;
{$IFDEF SERVER}
var
  ItemDal:TCmEnterpriseEmpDAL;
  CreateParcelFlg:Boolean;
begin
  if (iItem<>nil) and (iSQLs<>nil) then
  begin
    ItemDal:=TCmEnterpriseEmpDAL.Create(fDBConn,fDBID);
    if dParcel=nil then
    begin
      dParcel:=TQBParcel.Create;;
      CreateParcelFlg:=True;
    end else begin
      CreateParcelFlg:=False;
    end;
    
    try
      if not BeforeTreatment(iItem,pmAdd,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if dIsCheck then
      begin
        if not BeforeCheck(iItem,pmAdd,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      
        if not Check(iItem,pmAdd,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      end;
            
      if not BeforeExecute(iItem,pmAdd,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if not ItemDal.GetInsertSQLs(iItem,iSQLs,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if not AfterTreatment(iItem,pmAdd,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
    finally
      FreeAndNil(ItemDal);
      if CreateParcelFlg then
      begin
        FreeAndNil(dParcel);
      end;
    end;
  end else begin
    oError:=Format(string('调用%s.GetAddSQLs单例函数错误!错误内容:传入的实体对象或SQL列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF} {$IFDEF CLIENT}
var
  MemStream:TMemoryStream;
  InParcel,OutParcel:TQBParcel;
  ErrorCode,ErrorText:string;
begin
  if (iItem<>nil) and (iSQLs<>nil) then
  begin
    MemStream:=TMemoryStream.Create;
    InParcel:=TQBParcel.Create;
    OutParcel:=TQBParcel.Create;
    try
      InParcel.PutAnsiStringGoods(AnsiString('Fn'),AnsiString('GetSaveSQLs'));
      InParcel.PutAnsiStringGoods(AnsiString('ObjName'),AnsiString(iItem.ClassName));
      InParcel.PutIntegerGoods(AnsiString('Method'),Ord(ePretreatmentMode.pmAdd));
      InParcel.PutAnsiStringGoods(AnsiString('ObjStr'),AnsiString(iItem.SaveToStr));
      InParcel.PutBooleanGoods(AnsiString('IsCheck'),dIsCheck);
      if fDllPlugin.BinaryRPC(AnsiString(fPluginID),EmptyAnsiStr,InParcel,OutParcel) then
      begin
        if not OutParcel.GoodsExists('error') then
        begin
          if OutParcel.GetStreamGoods(AnsiString('SQLs'),MemStream) then
          begin
            iSQLs.LoadFromStream(MemStream);
          end else begin
            oError:=Format(string('调用%s.GetAddSQLs单例函数错误! 错误内容:获取SQLs流失败!'),[Self.ClassName]);
            Result:=False;
            Exit;
          end;
        end else begin
          oError:=Format(string('调用%s.GetAddSQLs单例函数-->调用%s插件-->%s'),[Self.ClassName,fPluginID,string(OutParcel.GetAnsiStringGoods('error'))]);
          Result:=False;
          Exit;
        end;
      end else begin
        fDllPlugin.GetLastError(ErrorCode,ErrorText);
        oError:=Format(string('调用%s.GetAddSQLs单例函数-->调用%s插件错误! 错误代码:%s 错误内容:%s'),[Self.ClassName,fPluginID,ErrorCode,ErrorText]);
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(MemStream);
      FreeAndNil(InParcel);
      FreeAndNil(OutParcel);
    end;
  end else begin
    oError:=Format(string('调用%s.GetAddSQLs单例函数错误! 错误内容:传入的实体对象或SQL列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF}

function TCmEnterpriseEmpBLL.GetAddSQLs(const iItems:TCmEnterpriseEmpList; const iSQLs:TStrings; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;
{$IFDEF SERVER}
var
  ItemDal:TCmEnterpriseEmpDAL;
  CreateParcelFlg:Boolean;
begin
  if (iItems<>nil) and (iSQLs<>nil) then
  begin
    ItemDal:=TCmEnterpriseEmpDAL.Create(fDBConn,fDBID);
    if dParcel=nil then
    begin
      dParcel:=TQBParcel.Create;;
      CreateParcelFlg:=True;
    end else begin
      CreateParcelFlg:=False;
    end;
    
    try
      if not BeforeTreatment(iItems,pmAdd,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if dIsCheck then
      begin
        if not BeforeCheck(iItems,pmAdd,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      
        if not Check(iItems,pmAdd,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      end;
      
      if not BeforeExecute(iItems,pmAdd,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if not ItemDal.GetInsertSQLs(iItems,iSQLs,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if not AfterTreatment(iItems,pmAdd,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(ItemDal);
      if CreateParcelFlg then
      begin
        FreeAndNil(dParcel);
      end;
    end;
  end else begin
    oError:=Format(string('调用%s.GetAddSQLs列表函数错误! 错误内容:传入的实体列表对象或SQL列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF} {$IFDEF CLIENT}
var
  MemStream:TMemoryStream;
  InParcel,OutParcel:TQBParcel;
  ErrorCode,ErrorText:string;
begin
  if (iItems<>nil) and (iSQLs<>nil) then
  begin
    MemStream:=TMemoryStream.Create;
    InParcel:=TQBParcel.Create;
    OutParcel:=TQBParcel.Create;
    try
      InParcel.PutAnsiStringGoods(AnsiString('Fn'),AnsiString('GetSaveSQLs'));
      InParcel.PutAnsiStringGoods(AnsiString('ObjName'),AnsiString(iItems.ClassName));
      InParcel.PutIntegerGoods(AnsiString('Method'),Ord(ePretreatmentMode.pmAdd));
      InParcel.PutAnsiStringGoods(AnsiString('ObjStr'),AnsiString(iItems.SaveToStr));
      InParcel.PutBooleanGoods(AnsiString('IsCheck'),dIsCheck);
      if fDllPlugin.BinaryRPC(AnsiString(fPluginID),EmptyAnsiStr,InParcel,OutParcel) then
      begin
        if not OutParcel.GoodsExists('error') then
        begin
          if OutParcel.GetStreamGoods(AnsiString('SQLs'),MemStream) then
          begin
            iSQLs.LoadFromStream(MemStream);
          end else begin
            oError:=Format(string('调用%s.GetAddSQLs列表函数错误!错误内容:获取SQLs流失败!'),[Self.ClassName]);
            Result:=False;
            Exit;
          end;
        end else begin
          oError:=Format(string('调用%s.GetAddSQLs列表函数-->调用%s插件-->%s'),[Self.ClassName,fPluginID,string(OutParcel.GetAnsiStringGoods('error'))]);
          Result:=False;
          Exit;
        end;
      end else begin
        fDllPlugin.GetLastError(ErrorCode,ErrorText);
        oError:=Format(string('调用%s.GetAddSQLs列表函数-->调用%s插件错误! 错误代码:%s 错误内容:%s'),[Self.ClassName,fPluginID,ErrorCode,ErrorText]);
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(MemStream);
      FreeAndNil(InParcel);
      FreeAndNil(OutParcel);
    end;
  end else begin
    oError:=Format(string('调用%s.GetAddSQLs列表函数错误! 错误内容:传入的实体列表对象或SQL列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF}

function TCmEnterpriseEmpBLL.Edit(const iItem:TCmEnterpriseEmp; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;
{$IFDEF SERVER}
var
  ItemDal:TCmEnterpriseEmpDAL;
  CreateParcelFlg:Boolean;
begin
  if (iItem<>nil) then
  begin
    ItemDal:=TCmEnterpriseEmpDAL.Create(fDBConn,fDBID);
    if dParcel=nil then
    begin
      dParcel:=TQBParcel.Create;;
      CreateParcelFlg:=True;
    end else begin
      CreateParcelFlg:=False;
    end;
    
    try
      if not BeforeTreatment(iItem,pmEdit,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if dIsCheck then
      begin
        if not BeforeCheck(iItem,pmEdit,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      
        if not Check(iItem,pmEdit,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      end;
             
      if not BeforeExecute(iItem,pmEdit,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end; 
      
      if ItemDal.UpdateToDB(iItem,oError) and 
        Reload(iItem,oError) then
      begin
      
      end else begin
        oError:=Format(string('调用%s.Edit单例函数-->%s'),[Self.ClassName,oError]);
        Result:=False;
        Exit;
      end;
      
      if not AfterTreatment(iItem,pmEdit,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(ItemDal);
      if CreateParcelFlg then
      begin
        FreeAndNil(dParcel);
      end;
    end;
  end else begin
    oError:=Format(string('调用%s.Edit单例函数错误! 错误内容:传入的实体对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF} {$IFDEF CLIENT}
var
  InParcel,OutParcel:TQBParcel;
  ErrorCode,ErrorText:string;
begin
  if (iItem<>nil) then
  begin
    InParcel:=TQBParcel.Create;
    OutParcel:=TQBParcel.Create;
    try
      InParcel.PutAnsiStringGoods(AnsiString('Fn'),AnsiString('SaveToDB'));
      InParcel.PutAnsiStringGoods(AnsiString('ObjName'),AnsiString(iItem.ClassName));
      InParcel.PutIntegerGoods(AnsiString('Method'),Ord(ePretreatmentMode.pmEdit));
      InParcel.PutAnsiStringGoods(AnsiString('ObjStr'),AnsiString(iItem.SaveToStr));
      InParcel.PutBooleanGoods(AnsiString('IsCheck'),dIsCheck);
      if fDllPlugin.BinaryRPC(AnsiString(fPluginID),EmptyAnsiStr,InParcel,OutParcel) then
      begin
        if not OutParcel.GoodsExists('error') then
        begin
          if not iItem.LoadFromStr(string(OutParcel.GetAnsiStringGoods(AnsiString('ObjStr'))),oError) then
          begin
            oError:=Format(string('调用%s.Edit单例函数-->%s'),[Self.ClassName,oError]);
            Result:=False;
            Exit;
          end;
        end else begin
          oError:=Format(string('调用%s.Edit单例函数->调用%s插件-->%s'),[Self.ClassName,fPluginID,string(OutParcel.GetAnsiStringGoods('error'))]);
          Result:=False;
          Exit;
        end;
      end else begin
        fDllPlugin.GetLastError(ErrorCode,ErrorText);
        oError:=Format(string('调用%s.Edit单例函数-->调用%s插件错误! 错误代码:%s 错误内容:%s'),[Self.ClassName,fPluginID,ErrorCode,ErrorText]);
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(InParcel);
      FreeAndNil(OutParcel);
    end;
  end else begin
    oError:=Format(string('调用%s.Edit单例函数错误! 错误内容:传入的实体对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF}

function TCmEnterpriseEmpBLL.Edit(const iItems:TCmEnterpriseEmpList; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;
{$IFDEF SERVER}
var
  ItemDal:TCmEnterpriseEmpDAL;
  CreateParcelFlg:Boolean;
begin
  if (iItems<>nil) then
  begin
    ItemDal:=TCmEnterpriseEmpDAL.Create(fDBConn,fDBID);
    if dParcel=nil then
    begin
      dParcel:=TQBParcel.Create;;
      CreateParcelFlg:=True;
    end else begin
      CreateParcelFlg:=False;
    end;

    try
      if not BeforeTreatment(iItems,pmEdit,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if dIsCheck then
      begin
        if not BeforeCheck(iItems,pmEdit,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      
        if not Check(iItems,pmEdit,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      end;
      
      if not BeforeExecute(iItems,pmEdit,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if ItemDal.UpdateToDB(iItems,oError) and 
        Reload(iItems,oError) then
      begin
      
      end else begin
        oError:=Format(string('调用%s.Edit列表函数-->%s'),[Self.ClassName,oError]);
        Result:=False;
        Exit;
      end;
      
      if not AfterTreatment(iItems,pmEdit,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(ItemDal);
      if CreateParcelFlg then
      begin
        FreeAndNil(dParcel);
      end;
    end;
  end else begin
    oError:=Format(string('调用%s.Edit列表函数错误! 错误内容:传入的实体列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF} {$IFDEF CLIENT}
var
  InParcel,OutParcel:TQBParcel;
  ErrorCode,ErrorText:string;
begin
  if (iItems<>nil) then
  begin
    InParcel:=TQBParcel.Create;
    OutParcel:=TQBParcel.Create;
    try
      InParcel.PutAnsiStringGoods(AnsiString('Fn'),AnsiString('SaveToDB'));
      InParcel.PutAnsiStringGoods(AnsiString('ObjName'),AnsiString(iItems.ClassName));
      InParcel.PutIntegerGoods(AnsiString('Method'),Ord(ePretreatmentMode.pmEdit));
      InParcel.PutAnsiStringGoods(AnsiString('ObjStr'),AnsiString(iItems.SaveToStr));
      InParcel.PutBooleanGoods(AnsiString('IsCheck'),dIsCheck);
      if fDllPlugin.BinaryRPC(AnsiString(fPluginID),EmptyAnsiStr,InParcel,OutParcel) then
      begin
        if not OutParcel.GoodsExists('error') then
        begin
          if not iItems.LoadFromStr(string(OutParcel.GetAnsiStringGoods(AnsiString('ObjStr'))),oError) then
          begin
            oError:=Format(string('调用%s.Edit列表函数-->%s'),[Self.ClassName,oError]);
            Result:=False;
            Exit;
          end;
        end else begin
          oError:=Format(string('调用%s.Edit列表函数-->调用%s插件-->%s'),[Self.ClassName,fPluginID,string(OutParcel.GetAnsiStringGoods('error'))]);
          Result:=False;
          Exit;
        end;
      end else begin
        fDllPlugin.GetLastError(ErrorCode,ErrorText);
        oError:=Format(string('调用%s.Edit列表函数-->调用%s插件错误! 错误代码:%s 错误内容:%s'),[Self.ClassName,fPluginID,ErrorCode,ErrorText]);
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(InParcel);
      FreeAndNil(OutParcel);
    end;
  end else begin
    oError:=Format(string('调用%s.Edit列表函数错误! 错误内容:传入的实体列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF}

function TCmEnterpriseEmpBLL.GetEditSQLs(const iItem:TCmEnterpriseEmp; const iSQLs:TStrings; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;
{$IFDEF SERVER}
var
  ItemDal:TCmEnterpriseEmpDAL;
  CreateParcelFlg:Boolean;
begin
  if (iItem<>nil) and (iSQLs<>nil) then
  begin
    ItemDal:=TCmEnterpriseEmpDAL.Create(fDBConn,fDBID);
    if dParcel=nil then
    begin
      dParcel:=TQBParcel.Create;;
      CreateParcelFlg:=True;
    end else begin
      CreateParcelFlg:=False;
    end;
    
    try
      if not BeforeTreatment(iItem,pmEdit,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if dIsCheck then
      begin
        if not BeforeCheck(iItem,pmEdit,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      
        if not Check(iItem,pmEdit,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      end;
      
      if not BeforeExecute(iItem,pmEdit,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if not ItemDal.GetUpdateSQLs(iItem,iSQLs,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if not AfterTreatment(iItem,pmEdit,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(ItemDal);
      if CreateParcelFlg then
      begin
        FreeAndNil(dParcel);
      end;
    end;
  end else begin
    oError:=Format(string('调用%s.GetEditSQLs单例函数错误! 错误内容:传入的实体对象或SQL列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF} {$IFDEF CLIENT}
var
  MemStream:TMemoryStream;
  InParcel,OutParcel:TQBParcel;
  ErrorCode,ErrorText:string;
begin
  if (iItem<>nil) and (iSQLs<>nil) then
  begin
    MemStream:=TMemoryStream.Create;
    InParcel:=TQBParcel.Create;
    OutParcel:=TQBParcel.Create;
    try
      InParcel.PutAnsiStringGoods(AnsiString('Fn'),AnsiString('GetSaveSQLs'));
      InParcel.PutAnsiStringGoods(AnsiString('ObjName'),AnsiString(iItem.ClassName));
      InParcel.PutIntegerGoods(AnsiString('Method'),Ord(ePretreatmentMode.pmEdit));
      InParcel.PutAnsiStringGoods(AnsiString('ObjStr'),AnsiString(iItem.SaveToStr));
      InParcel.PutBooleanGoods(AnsiString('IsCheck'),dIsCheck);
      if fDllPlugin.BinaryRPC(AnsiString(fPluginID),EmptyAnsiStr,InParcel,OutParcel) then
      begin
        if not OutParcel.GoodsExists('error') then
        begin
          if OutParcel.GetStreamGoods(AnsiString('SQLs'),MemStream) then
          begin
            iSQLs.LoadFromStream(MemStream);
          end else begin
            oError:=Format(string('调用%s.GetEditSQLs单例函数错误! 错误内容:获取SQLs流失败!'),[Self.ClassName]);
            Result:=False;
            Exit;
          end;
        end else begin
          oError:=Format(string('调用%s.GetEditSQLs单例函数-->调用%s插件-->%s'),[Self.ClassName,fPluginID,string(OutParcel.GetAnsiStringGoods('error'))]);
          Result:=False;
          Exit;
        end;
      end else begin
        fDllPlugin.GetLastError(ErrorCode,ErrorText);
        oError:=Format(string('调用%s.GetEditSQLs单例函数-->调用%s插件错误! 错误代码:%s 错误内容:%s'),[Self.ClassName,fPluginID,ErrorCode,ErrorText]);
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(MemStream);
      FreeAndNil(InParcel);
      FreeAndNil(OutParcel);
    end;
  end else begin
    oError:=Format(string('调用%s.GetEditSQLs单例函数错误! 错误内容:传入的实体对象或SQL列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF}

function TCmEnterpriseEmpBLL.GetEditSQLs(const iItems:TCmEnterpriseEmpList; const iSQLs:TStrings; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;
{$IFDEF SERVER}
var
  ItemDal:TCmEnterpriseEmpDAL;
  CreateParcelFlg:Boolean;
begin
  if (iItems<>nil) and (iSQLs<>nil) then
  begin
    ItemDal:=TCmEnterpriseEmpDAL.Create(fDBConn,fDBID);
    if dParcel=nil then
    begin
      dParcel:=TQBParcel.Create;;
      CreateParcelFlg:=True;
    end else begin
      CreateParcelFlg:=False;
    end;
    
    try
      if not BeforeTreatment(iItems,pmEdit,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if dIsCheck then
      begin
        if not BeforeCheck(iItems,pmEdit,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
        
        if not Check(iItems,pmEdit,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      end;
      
      if not BeforeExecute(iItems,pmEdit,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if not ItemDal.GetUpdateSQLs(iItems,iSQLs,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if not AfterTreatment(iItems,pmEdit,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(ItemDal);
      if CreateParcelFlg then
      begin
        FreeAndNil(dParcel);
      end;
    end;
  end else begin
    oError:=Format(string('调用%s.GetEditSQLs列表函数错误! 错误内容:传入的实体列表对象或SQL列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF} {$IFDEF CLIENT}
var
  MemStream:TMemoryStream;
  InParcel,OutParcel:TQBParcel;
  ErrorCode,ErrorText:string;
begin
  if (iItems<>nil) and (iSQLs<>nil) then
  begin
    MemStream:=TMemoryStream.Create;
    InParcel:=TQBParcel.Create;
    OutParcel:=TQBParcel.Create;
    try
      InParcel.PutAnsiStringGoods(AnsiString('Fn'),AnsiString('GetSaveSQLs'));
      InParcel.PutAnsiStringGoods(AnsiString('ObjName'),AnsiString(iItems.ClassName));
      InParcel.PutIntegerGoods(AnsiString('Method'),Ord(ePretreatmentMode.pmEdit));
      InParcel.PutAnsiStringGoods(AnsiString('ObjStr'),AnsiString(iItems.SaveToStr));
      InParcel.PutBooleanGoods(AnsiString('IsCheck'),dIsCheck);
      if fDllPlugin.BinaryRPC(AnsiString(fPluginID),EmptyAnsiStr,InParcel,OutParcel) then
      begin
        if not OutParcel.GoodsExists('error') then
        begin
          if OutParcel.GetStreamGoods(AnsiString('SQLs'),MemStream) then
          begin
            iSQLs.LoadFromStream(MemStream);
          end else begin
            oError:=Format(string('调用%s.GetEditSQLs列表函数错误! 错误内容:获取SQLs流失败!'),[Self.ClassName]);
            Result:=False;
            Exit;
          end;
        end else begin
          oError:=Format(string('调用%s.GetEditSQLs列表函数-->调用%s插件-->%s'),[Self.ClassName,fPluginID,string(OutParcel.GetAnsiStringGoods('error'))]);
          Result:=False;
          Exit;
        end;
      end else begin
        fDllPlugin.GetLastError(ErrorCode,ErrorText);
        oError:=Format(string('调用%s.GetEditSQLs列表函数-->调用%s插件错误! 错误代码:%s 错误内容:%s'),[Self.ClassName,fPluginID,ErrorCode,ErrorText]);
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(MemStream);
      FreeAndNil(InParcel);
      FreeAndNil(OutParcel);
    end;
  end else begin
    oError:=Format(string('调用%s.GetEditSQLs列表函数错误! 错误内容:传入的实体列表对象或SQL列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF}

function TCmEnterpriseEmpBLL.Delete(const iItem:TCmEnterpriseEmp; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;
{$IFDEF SERVER}
var
  ItemDal:TCmEnterpriseEmpDAL;
  CreateParcelFlg:Boolean;
begin
  if (iItem<>nil) then
  begin
    ItemDal:=TCmEnterpriseEmpDAL.Create(fDBConn,fDBID);
    if dParcel=nil then
    begin
      dParcel:=TQBParcel.Create;;
      CreateParcelFlg:=True;
    end else begin
      CreateParcelFlg:=False;
    end;
    
    try
      if not BeforeTreatment(iItem,pmDelete,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if dIsCheck then
      begin
        if not BeforeCheck(iItem,pmDelete,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      
        if not Check(iItem,pmDelete,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      end;
      
      if not BeforeExecute(iItem,pmDelete,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if not ItemDal.DeleteToDB(iItem,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if not AfterTreatment(iItem,pmDelete,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(ItemDal);
      if CreateParcelFlg then
      begin
        FreeAndNil(dParcel);
      end;
    end;
  end else begin
    oError:=Format(string('调用%s.Delete单例函数错误!错误内容:传入的实体对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF} {$IFDEF CLIENT}
var
  InParcel,OutParcel:TQBParcel;
  ErrorCode,ErrorText:string;
begin
  if (iItem<>nil) then
  begin
    InParcel:=TQBParcel.Create;
    OutParcel:=TQBParcel.Create;
    try
      InParcel.PutAnsiStringGoods(AnsiString('Fn'),AnsiString('SaveToDB'));
      InParcel.PutAnsiStringGoods(AnsiString('ObjName'),AnsiString(iItem.ClassName));
      InParcel.PutIntegerGoods(AnsiString('Method'),Ord(ePretreatmentMode.pmDelete));
      InParcel.PutAnsiStringGoods(AnsiString('ObjStr'),AnsiString(iItem.SaveToStr));
      InParcel.PutBooleanGoods(AnsiString('IsCheck'),dIsCheck);
      if fDllPlugin.BinaryRPC(AnsiString(fPluginID),EmptyAnsiStr,InParcel,OutParcel) then
      begin
        if not OutParcel.GoodsExists('error') then
        begin
          iItem.ResetObject;
        end else begin
          oError:=Format(string('调用%s.Delete单例函数-->调用%s插件-->%s'),[Self.ClassName,fPluginID,string(OutParcel.GetAnsiStringGoods('error'))]);
          Result:=False;
          Exit;
        end;
      end else begin
        fDllPlugin.GetLastError(ErrorCode,ErrorText);
        oError:=Format(string('调用%s.Delete单例函数-->调用%s插件错误! 错误代码:%s 错误内容:%s'),[Self.ClassName,fPluginID,ErrorCode,ErrorText]);
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(InParcel);
      FreeAndNil(OutParcel);
    end;
  end else begin
    oError:=Format(string('调用%s.Delete单例函数错误! 错误内容:传入的实体对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF}

function TCmEnterpriseEmpBLL.Delete(const iItems:TCmEnterpriseEmpList; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;
{$IFDEF SERVER}
var
  ItemDal:TCmEnterpriseEmpDAL;
  CreateParcelFlg:Boolean;
begin
  if (iItems<>nil) then
  begin
    ItemDal:=TCmEnterpriseEmpDAL.Create(fDBConn,fDBID);
    if dParcel=nil then
    begin
      dParcel:=TQBParcel.Create;;
      CreateParcelFlg:=True;
    end else begin
      CreateParcelFlg:=False;
    end;
    
    try
      if not BeforeTreatment(iItems,pmDelete,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if dIsCheck then
      begin
        if not BeforeCheck(iItems,pmDelete,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      
        if not Check(iItems,pmDelete,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      end;
      
      if not BeforeExecute(iItems,pmDelete,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if not ItemDal.DeleteToDB(iItems,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if not AfterTreatment(iItems,pmDelete,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(ItemDal);
      if CreateParcelFlg then
      begin
        FreeAndNil(dParcel);
      end;
    end;
  end else begin
    oError:=Format(string('调用%s.Delete列表函数错误! 错误内容:传入的实体列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF} {$IFDEF CLIENT}
var
  InParcel,OutParcel:TQBParcel;
  ErrorCode,ErrorText:string;
begin
  if (iItems<>nil) then
  begin
    InParcel:=TQBParcel.Create;
    OutParcel:=TQBParcel.Create;
    try
      InParcel.PutAnsiStringGoods(AnsiString('Fn'),AnsiString('SaveToDB'));
      InParcel.PutAnsiStringGoods(AnsiString('ObjName'),AnsiString(iItems.ClassName));
      InParcel.PutIntegerGoods(AnsiString('Method'),Ord(ePretreatmentMode.pmDelete));
      InParcel.PutAnsiStringGoods(AnsiString('ObjStr'),AnsiString(iItems.SaveToStr));
      InParcel.PutBooleanGoods(AnsiString('IsCheck'),dIsCheck);
      if fDllPlugin.BinaryRPC(AnsiString(fPluginID),EmptyAnsiStr,InParcel,OutParcel) then
      begin
        if not OutParcel.GoodsExists('error') then
        begin
          iItems.ResetObject;
        end else begin
          oError:=Format(string('调用%s.Delete列表函数-->调用%s插件-->%s'),[Self.ClassName,fPluginID,string(OutParcel.GetAnsiStringGoods('error'))]);
          Result:=False;
          Exit;
        end;
      end else begin
        fDllPlugin.GetLastError(ErrorCode,ErrorText);
        oError:=Format(string('调用%s.Delete列表函数-->调用%s插件错误! 错误代码:%s 错误内容:%s'),[Self.ClassName,fPluginID,ErrorCode,ErrorText]);
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(InParcel);
      FreeAndNil(OutParcel);
    end;
  end else begin
    oError:=Format(string('调用%s.Delete列表函数错误!错误内容:传入的实体列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF}

function TCmEnterpriseEmpBLL.GetDeleteSQLs(const iItem:TCmEnterpriseEmp; const iSQLs:TStrings; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;
{$IFDEF SERVER}
var
  ItemDal:TCmEnterpriseEmpDAL;
  CreateParcelFlg:Boolean;
begin
  if (iItem<>nil) and (iSQLs<>nil) then
  begin
    ItemDal:=TCmEnterpriseEmpDAL.Create(fDBConn,fDBID);
    if dParcel=nil then
    begin
      dParcel:=TQBParcel.Create;;
      CreateParcelFlg:=True;
    end else begin
      CreateParcelFlg:=False;
    end;
    
    try
      if not BeforeTreatment(iItem,pmDelete,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if dIsCheck then
      begin
        if not BeforeCheck(iItem,pmDelete,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      
        if not Check(iItem,pmDelete,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      end;
      
      if not BeforeExecute(iItem,pmDelete,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if not ItemDal.GetDeleteSQLs(iItem,iSQLs,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if not AfterTreatment(iItem,pmDelete,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(ItemDal);
      if CreateParcelFlg then
      begin
        FreeAndNil(dParcel);
      end;
    end;
  end else begin
    oError:=Format(string('调用%s.GetDeleteSQLs单例函数错误! 错误内容:传入的实体对象或SQL列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF} {$IFDEF CLIENT}
var
  MemStream:TMemoryStream;
  InParcel,OutParcel:TQBParcel;
  ErrorCode,ErrorText:string;
begin
  if (iItem<>nil) and (iSQLs<>nil) then
  begin
    MemStream:=TMemoryStream.Create;
    InParcel:=TQBParcel.Create;
    OutParcel:=TQBParcel.Create;
    try
      InParcel.PutAnsiStringGoods(AnsiString('Fn'),AnsiString('GetSaveSQLs'));
      InParcel.PutAnsiStringGoods(AnsiString('ObjName'),AnsiString(iItem.ClassName));
      InParcel.PutIntegerGoods(AnsiString('Method'),Ord(ePretreatmentMode.pmDelete));
      InParcel.PutAnsiStringGoods(AnsiString('ObjStr'),AnsiString(iItem.SaveToStr));
      InParcel.PutBooleanGoods(AnsiString('IsCheck'),dIsCheck);
      if fDllPlugin.BinaryRPC(AnsiString(fPluginID),EmptyAnsiStr,InParcel,OutParcel) then
      begin
        if not OutParcel.GoodsExists('error') then
        begin
          if OutParcel.GetStreamGoods(AnsiString('SQLs'),MemStream) then
          begin
            iSQLs.LoadFromStream(MemStream);
          end else begin
            oError:=Format(string('调用%s.GetDeleteSQLs单例函数错误! 错误内容:获取SQLs流失败!'),[Self.ClassName]);
            Result:=False;
            Exit;
          end;
        end else begin
          oError:=Format(string('调用%s.GetDeleteSQLs单例函数-->调用%s插件-->%s'),[Self.ClassName,fPluginID,string(OutParcel.GetAnsiStringGoods('error'))]);
          Result:=False;
          Exit;
        end;
      end else begin
        fDllPlugin.GetLastError(ErrorCode,ErrorText);
        oError:=Format(string('调用%s.GetDeleteSQLs单例函数-->调用%s插件错误! 错误代码:%s 错误内容:%s'),[Self.ClassName,fPluginID,ErrorCode,ErrorText]);
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(MemStream);
      FreeAndNil(InParcel);
      FreeAndNil(OutParcel);
    end;
  end else begin
    oError:=Format(string('调用%s.GetDeleteSQLs单例函数错误! 错误内容:传入的实体对象或SQL列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF}

function TCmEnterpriseEmpBLL.GetDeleteSQLs(const iItems:TCmEnterpriseEmpList; const iSQLs:TStrings; out oError:string; const dIsCheck:Boolean=True; dParcel:TQBParcel=nil):Boolean;
{$IFDEF SERVER}
var
  ItemDal:TCmEnterpriseEmpDAL;
  CreateParcelFlg:Boolean;
begin
  if (iItems<>nil) and (iSQLs<>nil) then
  begin
    ItemDal:=TCmEnterpriseEmpDAL.Create(fDBConn,fDBID);
    if dParcel=nil then
    begin
      dParcel:=TQBParcel.Create;;
      CreateParcelFlg:=True;
    end else begin
      CreateParcelFlg:=False;
    end;
    
    try
      if not BeforeTreatment(iItems,pmDelete,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if dIsCheck then
      begin
        if not BeforeCheck(iItems,pmDelete,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      
        if not Check(iItems,pmDelete,dParcel,oError) then
        begin
          Result:=False;
          Exit;
        end;
      end;
      
      if not BeforeExecute(iItems,pmDelete,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if not ItemDal.GetDeleteSQLs(iItems,iSQLs,oError) then
      begin
        Result:=False;
        Exit;
      end;
      
      if not AfterTreatment(iItems,pmDelete,dParcel,oError) then
      begin
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(ItemDal);
      if CreateParcelFlg then
      begin
        FreeAndNil(dParcel);
      end;
    end;
  end else begin
    oError:=Format(string('调用%s.GetDeleteSQLs列表函数错误! 错误内容:传入的实体列表对象或SQL列表对象为空!'),[Self.ClassName]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF} {$IFDEF CLIENT}
var
  MemStream:TMemoryStream;
  InParcel,OutParcel:TQBParcel;
  ErrorCode,ErrorText:string;
begin
  if (iItems<>nil) and (iSQLs<>nil) then
  begin
    MemStream:=TMemoryStream.Create;
    InParcel:=TQBParcel.Create;
    OutParcel:=TQBParcel.Create;
    try
      InParcel.PutAnsiStringGoods(AnsiString('Fn'),AnsiString('GetSaveSQLs'));
      InParcel.PutAnsiStringGoods(AnsiString('ObjName'),AnsiString(iItems.ClassName));
      InParcel.PutIntegerGoods(AnsiString('Method'),Ord(ePretreatmentMode.pmDelete));
      InParcel.PutAnsiStringGoods(AnsiString('ObjStr'),AnsiString(iItems.SaveToStr));
      InParcel.PutBooleanGoods(AnsiString('IsCheck'),dIsCheck);
      if fDllPlugin.BinaryRPC(AnsiString(fPluginID),EmptyAnsiStr,InParcel,OutParcel) then
      begin
        if not OutParcel.GoodsExists('error') then
        begin
          if OutParcel.GetStreamGoods(AnsiString('SQLs'),MemStream) then
          begin
            iSQLs.LoadFromStream(MemStream);
          end else begin
            oError:=Format(string('调用%s.GetDeleteSQLs列表函数错误! 错误内容:获取SQLs流失败!'),[Self.ClassName]);
            Result:=False;
            Exit;
          end;
        end else begin
          oError:=Format(string('调用%s.GetDeleteSQLs列表函数-->调用%s插件-->%s'),[Self.ClassName,fPluginID,string(OutParcel.GetAnsiStringGoods('error'))]);
          Result:=False;
          Exit;
        end;
      end else begin
        fDllPlugin.GetLastError(ErrorCode,ErrorText);
        oError:=Format(string('调用%s.GetDeleteSQLs列表函数-->调用%s插件错误! 错误代码:%s 错误内容:%s'),[Self.ClassName,fPluginID,ErrorCode,ErrorText]);
        Result:=False;
        Exit;
      end;
    finally
      FreeAndNil(MemStream);
      FreeAndNil(InParcel);
      FreeAndNil(OutParcel);
    end;
  end else begin
    oError:=Format(string('调用%s.GetDeleteSQLs列表函数错误! 错误内容:传入的实体列表对象或SQL列表对象为空!'),[]);
    Result:=False;
    Exit;
  end;
  Result:=True;
end;
{$ENDIF}
end.
